/*  This is mada by Kent    
 *  This source is made by Funms Team
 *  功能：BOSS进阶扎昆
 *  @Author Kent 
 */

function init() {
    em.setProperty("state", "0");
    em.setProperty("leader", "true");
}

function setup(eim, leaderid) {
    em.setProperty("state", "1");
    em.setProperty("leader", "true");
    var eim = em.newInstance("BossZakum_CHAOS");
    eim.setProperty("zakSummoned", "0");
    eim.createInstanceMap(280030001).resetFully();
    eim.startEventTimer(4500000); //1 hr 15 min
    return eim;
}

function playerEntry(eim, player) {
    var map = eim.getMapInstance(0);
    player.changeMap(map, map.getPortal(0));
}

function playerRevive(eim, player) {
    return false;
}

function changedMap(eim, player, mapid) {
    if (mapid != 280030001) {
        eim.unregisterPlayer(player);

        if (eim.disposeIfPlayerBelow(0, 0)) {
            em.setProperty("state", "0");
            em.setProperty("leader", "true");
        }
    }
}

function playerDisconnected(eim, player) {
    return 0;
}

function scheduledTimeout(eim) {
    end(eim);
}

var Count = 0;
function monsterValue(eim, mobId) {
    switch (mobId) {
          case 8800103:
		  case 8800104:
		  case 8800105:
		  case 8800106:
		  case 8800107:
		  case 8800108:
		  case 8800109:
		  case 8800110:
            for (i = 0; i < eim.getPlayers().size(); i++) {
              if (!eim.getPlayers().get(i).isAdmin() && em.getProperty("Count") == 0) {
				   em.setProperty("Count", "1");
                   eim.getPlayers().get(i).setPQLog(""+ em.getProperty("PQLog") +"");
                }
			}		
            break;
			
		  case 8800102:
		    for (i = 0; i < eim.getPlayers().size(); i++) {
				 eim.getPlayers().get(i).openNpc(9900002, "BOSS奖励结算");
			}
			eim.startEventTimer(1 * 60 * 1000);	
		    break;
    }
    return 1;
}

function playerExit(eim, player) {
    eim.unregisterPlayer(player);

    if (eim.disposeIfPlayerBelow(0, 0)) {
        em.setProperty("state", "0");
        em.setProperty("leader", "true");
    }
}

function end(eim) {
    eim.disposeIfPlayerBelow(100, 211042300);
    em.setProperty("state", "0");
    em.setProperty("leader", "true");
    em.setProperty("zakSummoned", "0");
}

function clearPQ(eim) {
    end(eim);
}

function allMonstersDead(eim) {
    if (em.getProperty("state").equals("1")) {
        em.setProperty("state", "2");
    } else if (em.getProperty("state").equals("2")) {
        em.setProperty("state", "3");
    }
    eim.restartEventTimer(1 * 60 * 1000);
}

function leftParty(eim, player) {
}
function disbandParty(eim) {
}
function playerDead(eim, player) {
}
function cancelSchedule() {
}
function pickUpItem(eim, player, itemID) {
}